package com.xzlcPT.service.impl;/**
 * Created by Administrator on 2017/8/10.
 */

import com.xzlcPT.bean.*;
import com.xzlcPT.dao.XzCompanyMapper;
import com.xzlcPT.dao.XzMsgMapper;
import com.xzlcPT.dao.XzPostionSendMapper;
import com.xzlcPT.dao.XzPostionSendMsgMapper;
import com.xzlcPT.service.XzPostionSendMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 甘汝雷
 * @create 2017-08-10 13:21
 **/
@Service("postionSendMsgService")
public class XzPostionSendMsgServiceImpl implements XzPostionSendMsgService {
    @Autowired
    private XzPostionSendMsgMapper postionSendMsgMapper;
    @Autowired
    private XzPostionSendMapper postionSendMapper;
    @Autowired
    private XzCompanyMapper companyMapper;
    @Autowired
    private XzMsgMapper msgMapper;

    @Override
    public int insertSelective(XzPostionSendMsg xzPostionSendMsg) {
        int i = postionSendMsgMapper.insertSelective(xzPostionSendMsg);
        return i;
    }

    @Override
    public int updateType(XzPostionSendMsg xzPostionSendMsg, XzLogin xzLogin, XzPostionSendMsg xzPostionSendMsg1) {
        int i = postionSendMsgMapper.updateByPrimaryKeySelective(xzPostionSendMsg);
        XzMsg xzMsg = new XzMsg();
        xzMsg.setMsgTital(xzLogin.getMember().getMemberName() + "面试邀请");
        xzMsg.setMsgContent(xzPostionSendMsg.getFiled3());
        xzMsg.setMsgSendId(xzLogin.getLoginId());
        xzMsg.setMsgSendName(xzLogin.getMember().getMemberName());
        XzPostionSend xzPostionSend = postionSendMapper.selectByPrimaryKey(xzPostionSendMsg1.getSendId());
        XzCompany xzCompany = companyMapper.selectByPrimaryKey(xzPostionSend.getCompanyId());
        xzMsg.setMsgReceiveId(xzCompany.getLoginId());
        xzMsg.setMsgReceiveName(xzCompany.getCompanyName());
        Date date = new Date();
        xzMsg.setMsgTime(date);
        xzMsg.setMsgType(4);
        xzMsg.setMsgIsread(0);
        xzMsg.setCreateTime(date);
        System.out.println(xzLogin);
        int j = msgMapper.insertSelective(xzMsg);
        xzCompany.setCompanyState(1);
        companyMapper.adoptCompany(xzCompany);
        return i;
    }

    @Override
    public int updateByPrimaryKeySelective(XzPostionSendMsg xzPostionSendMsg) {
        int i = postionSendMsgMapper.updateByPrimaryKeySelective(xzPostionSendMsg);
        return i;
    }

    @Override
    public XzPostionSendMsg selectBySendId(Long sendId) {
        return postionSendMsgMapper.selectBySendId(sendId);
    }

    @Override
    public XzPostionSendMsg selByKey(Long pmsgId) {
        XzPostionSendMsg xzPostionSendMsg = postionSendMsgMapper.selectByPrimaryKey(pmsgId);
        return xzPostionSendMsg;
    }


}
